/* ProviderColl.java
 * 
 * This is a collection of the providers which are read in from
 * the input file and created by the ProviderCMD class. It is a 
 * treemap ordered by name.
 *  
 * Greg Warner
 * Derek Dupuis
 * Michael Dixey
 * Alex Schwartz
 */

import java.util.*;

public class ProviderColl extends TreeMap< String, Provider >
   implements CollectionIF< Provider >
{
   public ProviderColl()
   {
      super();
   }
   
   //-----------------------------CollectionIF methods-----------------
   
   // adds a provider to the list
   public boolean add( Provider p )
   {
      if ( ! this.containsKey( p.name( ) ) )
      {
         this.put( p.name(), p );
         return true;
      }
      else
      {
         System.err.printf( "Provider of %s already exists!\n",
                           p.name() );
         return false;
      }
   }
   
   // returns true if provider is in the list already
   public boolean find( String s )
   {
      return this.containsKey( s );
   }
   
   public Provider get( String s )
   {
      return super.get( s );
   }
   
   // returns a string representation of the provider
   public String toString()
   {
      String s = "PROVIDERS:\n";
      
      Set    p = this.keySet( );
      
      
      Iterator iter = p.iterator();
      
      while( iter.hasNext() )
         s = s + this.get( iter.next() ).toString() + '\n';
      
      return s;
   }
}